package com.twelve.controller;


import com.twelve.bean.Collumn;
import com.twelve.service.CollumnService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
@RequestMapping("/collumn")
public class CollumnController {
	@Autowired
	private CollumnService service;
	@RequestMapping("")
	public String collumn(HttpServletRequest request){
		return "collumnpage";
	} 
	
	@ResponseBody
	@RequestMapping("list")
	public String list(HttpServletRequest request){
		String page = request.getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数
		String rows = request.getParameter("rows"); // 取得每页显示行数，,注意这是jqgrid自身的参数
		return service.getShowJson(Integer.parseInt(page) , Integer.parseInt(rows));
	}
	
	@ResponseBody
	@RequestMapping(value = "operation" , method={RequestMethod.POST})
	public String operationCollumn(HttpServletRequest request , Collumn collumn){
		boolean result = false;
		String oper = request.getParameter("oper");
		switch (oper) {
		case "edit":
			result = service.updateById(collumn);
			break;
		case "del":
			result = service.deleteById(collumn.getId());
			break;
		case "add":
			result = service.insert(collumn);
			break;
		}
		return "aaaa";
	}

}